using System.Reflection;

try
{
    Console.Title = Assembly.GetCallingAssembly().FullName ?? "";
    NLogUtil.WriteFileLog(NLog.LogLevel.Trace, LogType.Web, "��վ���", "��վ����ɹ�");

    var builder = WebApplication.CreateBuilder(args);
    var Configuration = builder.Configuration;

    //log&config
    builder.Logging.SetMinimumLevel(LogLevel.Trace);
    builder.Host.UseNLog();
    builder.Services.AddConfig(Configuration);

    //autofac
    builder.Host
        .UseServiceProviderFactory(new AutofacServiceProviderFactory())
        .ConfigureContainer<ContainerBuilder>(
        builder =>
        {
            builder.RegisterModule(new AutofacModule(Configuration));
        });

    var app = builder.Build();

    //seed
    var seed = args.Contains("seed");
    if (seed)
    {
        args = args.Except(new[] { "seed" }).ToArray();

        EnsureSeedData seedData = new EnsureSeedData();
        seedData.EnsureSeedDataAsync(app.Services).Wait();
    }

    InternalApp.ServiceProvider = app.Services;
    app.UseConfig().Run();

}
catch (Exception ex)
{
    NLogUtil.WriteFileLog(NLog.LogLevel.Error, LogType.Web, "��վ���", "��ʼ�������쳣", ex);
}

